package com.randi.monitor.dto.service;

import com.randi.common.utils.MathFloatUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * CPU信息
 *
 * @author randi
 */
@Data
@ApiModel(value = "Cpu", description = "CPU相关信息")
public class Cpu {

    @ApiModelProperty(value = "核心数")
    private int cores;

    @ApiModelProperty(value = "CPU总的使用率")
    private double total;

    @ApiModelProperty(value = "CPU系统使用率")
    private double system;

    @ApiModelProperty(value = "CPU用户使用率")
    private double used;

    @ApiModelProperty(value = "CPU当前等待率")
    private double wait;

    @ApiModelProperty(value = "CPU当前空闲率")
    private double free;

    public double getTotal() {
        return MathFloatUtils.round(MathFloatUtils.mul(total, 100), 2);
    }

    public double getSystem() {
        return MathFloatUtils.round(MathFloatUtils.mul(system / total, 100), 2);
    }

    public double getUsed() {
        return MathFloatUtils.round(MathFloatUtils.mul(used / total, 100), 2);
    }

    public double getUsage() {
        return MathFloatUtils.mul(MathFloatUtils.div(this.total - this.free, this.total, 4), 100);
    }

    public double getWait() {
        return MathFloatUtils.round(MathFloatUtils.mul(wait / total, 100), 2);
    }

    public double getFree() {
        return MathFloatUtils.round(MathFloatUtils.mul(free / total, 100), 2);
    }

}
